<?php
namespace backend\models;

use Yii;
use yii\base\Model;
use yii\base\Exception;
use common\models\Employees;
use common\models\EmpDepart;

class EmpDepartForm extends Model
{
	public $did;
	public $eid;
	public $identity;

	public function formName()
    {
        return '';
    }

	public function rules()
	{
		return [
			[['did', 'eid', 'identity'], 'safe']
		];
	}

	public function update($id)
	{
		EmpDepart::deleteAll(['eid' => $id]);

		foreach ($this->did as $key => $val) {
			$emp_depart = new EmpDepart;
			$emp_depart->did = $val;
			$emp_depart->eid = $id;
			$emp_depart->identity = $this->identity[$key];
			$emp_depart->save(false);
		}

		return true;
	}


}	